//
//  RFDemoOneViewController.m
//  RFIXiOSDemo
//
//  Created by bill bai on 2025/1/21.
//

#import "RFDemoOneViewController.h"

#import <RFIX/RFIXAnnotations.h>

@interface RFDemoOneViewController ()

@end

@implementation RFDemoOneViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  self.navigationItem.title = @"Demo One";
}

// RFIX 的 OCSCompiler 在编译代码时，会定义 __OCS_COMPILER__ 宏。
// 因此，可以使用 __OCS_COMPILER__ 宏来区分 RFIX 编译环墋和 Xcode 编译环境。
#if __OCS_COMPILER__

- (void)viewWillAppear:(BOOL)animated RFIX_METHOD() {
  [super viewWillAppear:animated];
  NSLog(@"viewWillAppear");
  [self.tableView reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView RFIX_METHOD() {
  NSLog(@"numberOfSectionsInTableView");
  return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section RFIX_METHOD() {
  NSLog(@"numberOfRowsInSection");
  return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath RFIX_METHOD() {
  UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  cell.textLabel.text = @"Hello, RFIX! (点我试试)";
  NSLog(@"cellForRowAtIndexPath");
  return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath RFIX_METHOD() {
  NSLog(@"begin didSelectRowAtIndexPath");
  [tableView deselectRowAtIndexPath:indexPath animated:YES];
  UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"RFIX" message:@"Hello, RFIX!" preferredStyle:UIAlertControllerStyleAlert];
  UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
  [alert addAction:ok];
  [self presentViewController:alert animated:YES completion:nil];
  NSLog(@"end didSelectRowAtIndexPath");
}


#else

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section __attribute__((annotate("@RFIX_METHOD@"))) {
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath RFIX_METHOD() {
  UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  cell.textLabel.text = @"Hello, Native! (No Patch)";
  NSLog(@"cellForRowAtIndexPath");
  return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath RFIX_METHOD() {
  [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#endif  // __OCS_COMPILER__

@end
